package com.customers.controller;

import com.alibaba.fastjson2.JSON;
import com.customers.entity.Customer;
import com.customers.service.CustomerService;
import com.customers.service.Impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/ContactUpdate")
public class ContactAdditionServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String customerJson = request.getParameter("Customer");

        System.out.println("customerJson:"+customerJson);
        Customer customer = JSON.parseObject(customerJson,Customer.class);
        System.out.println("customer:"+customer);

        try {
            CustomerService customerService = (CustomerServiceImpl) request.getServletContext().getAttribute("CustomerService");
            String sql = "contactIns";
            customerService.addContact(customer,sql);
//            ContactFormService.addContact(customer);
//          缺少返回新增联系人的id
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
